using Sustainalytics.ESG.Entities;
using System;

namespace Sustainalytics.ScreeningTool.Synchronization
{
    public static class DateTimeExtensions
    {
        public static DateTime? NullIfDefaultValue(this DateTime dateTime)
            => dateTime != default(DateTime) ? dateTime : (DateTime?)null;

        public static DateTime? NullIfDefaultValue(this DateTime? dateTime)
            => dateTime?.NullIfDefaultValue();

        public static DateTime? NullIfMinValue(this DateTime dateTime)
            => dateTime != DateTime.MinValue ? dateTime : (DateTime?)null;

        public static DateTime? NullIfMinValue(this DateTime? dateTime)
            => dateTime?.NullIfMinValue();

        public static Timestamped<DateTime?> NullIfMinValue(this Timestamped<DateTime> timestamped)
            => timestamped?.Bind<DateTime?>(x => NullIfMinValue(x));
    }
}
